<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="resource/js/jquery-3.2.1.js"></script>
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
	function topage(pageNum){
		$("[name=pageNum]").val(pageNum);
		$("form").submit();
	}
	//退租
	function tui(id){
		
		location.href="tui?id="+id;
		
	}
	//删除
	function del(id){
		if (confirm("确定要删除吗")) {
		$.post(
				"del",
				{id:id},
				function(msg){
					if (msg) {
						alert("删除成功");
						location.reload();
					}else {
						alert("删除失败")
					}
				},"json"
			)
		}
	}
	//出租
	function chu(id){
		location.href="chu?id="+id;
	}
</script>
<form action="list" method="post">
	<input type="hidden" name="pageNum">
	小区名称<input type="text" name="name">
	出租状态<select name="status">
		<option value="">----选择状态-----</option>
		<option value="1">待租</option>
		<option value="0">已租</option>
	</select>
	<input type="submit" value="搜索">
</form>
<table>
	<tr>
		<th>编号</th>
		<th>小区名称</th>
		<th>单元楼</th>
		<th>门牌号</th>
		<th>实景图</th>
		<th>状态</th>
		<th>挂牌时间</th>
		<th>出租时间</th>
		<th>户型</th>
		<th>操作</th>
	</tr>
	<c:forEach items="${info.list }" var="c">
		<tr>
			<td>${c.id }</td>
			<td>${c.name }</td>
			<td>${c.building }</td>
			<td>${c.number }</td>
			<td>
				<c:if test="${c.picture!=null }">
					<img  src="${c.picture }" width="40px;">
				</c:if>
			</td>
			<td>${c.status==0?'已租':'待租' }</td>
			<td>
				<fmt:formatDate value="${c.listingTime }" pattern="yyyy-MM-dd"/>
			</td>
			<td>
				<fmt:formatDate value="${c.rentalTime }" pattern="yyyy-MM-dd"/>
			</td>
			<td>${c.typeName }</td>
			<td>
				<c:if test="${c.status==0 }">
					<input type="button" value="退租" onclick="tui(${c.id })">
				</c:if>
				<c:if test="${c.status==1 }">
					<input type="button" value="删除" onclick="del(${c.id })">
					<input type="button" value="出租" onclick="chu(${c.id })">
				</c:if>
			</td>
		</tr>
	</c:forEach>
	<tr>
		<td colspan="11">
			<input type="button" value="上一页" onclick="topage(${info.prePage})">
			&emsp;&emsp;   ${info.pageNum }/${info.pages }   &emsp;&emsp;
			<input type="button" value="下一页" onclick="topage(${info.nextPage})">
		</td>
	</tr>
</table>
</body>
</html>